﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Web.Script.Serialization;
using CodeMatrix.Data.Entities;


    /// <summary>
    /// Summary description for Service
    /// </summary>
    [WebService(Namespace = "http://tempuri.org/")]
    [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
    [System.ComponentModel.ToolboxItem(false)]
    // To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
    [System.Web.Script.Services.ScriptService]
    public class DataServices : System.Web.Services.WebService
    {

        [WebMethod]
        public string GetExam(int testingId)
        {
            string outData = string.Empty;
            ExamObject examObject = new ExamObject();
            examObject.Time = 10;

            for (int i = 0; i < 100; i++)
            {
                QuestionObject iQuestionObject = new QuestionObject();
                iQuestionObject.QuestionId = i;
                iQuestionObject.Answer = string.Format("Answers : {0}", Guid.NewGuid());
                int iCorrectChoice = new Random().Next(0, 3);
                for (int j = 0; j < 4; j++)
                {
                    Choice jChoice = new Choice();
                    jChoice.Detail = string.Format("Choice : {0}", Guid.NewGuid());
                    jChoice.QuestionId = i;
                    jChoice.IsCorrect = iCorrectChoice == j;
                    switch (j)
                    {
                        case 0:
                            jChoice.Label = "A";
                            break;
                        case 1:
                            jChoice.Label = "B";
                            break;
                        case 2:
                            jChoice.Label = "C";
                            break;
                        case 3:
                            jChoice.Label = "D";
                            break;
                    }

                    iQuestionObject.Choices.Add(jChoice);
                }
                iQuestionObject.Description = string.Format("Description {0}", Guid.NewGuid());
                examObject.Questions.Add(iQuestionObject);
            }


            JavaScriptSerializer js = new JavaScriptSerializer();
            outData = js.Serialize(examObject);

            return outData;
        }

        [WebMethod]
        public string GetExamResult(string examSubmitObject)
        {
            JavaScriptSerializer js = new JavaScriptSerializer();
            ExamSubmitObject obj = js.Deserialize<ExamSubmitObject>(examSubmitObject);

            List<ResultObject> cResultObject = new List<ResultObject>();
            cResultObject.Add(new ResultObject());
            cResultObject.Add(new ResultObject());
            cResultObject.Add(new ResultObject());
            cResultObject.Add(new ResultObject());
            cResultObject.Add(new ResultObject());

            return js.Serialize(cResultObject.ToArray());
        }

    }

